package com.wlr.littleprogram.controller;

import com.wlr.littleprogram.dto.Result;
import com.wlr.littleprogram.service.SpiderCpuInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lrwang
 * @version 1.0
 * @date 2022/7/23 18:03
 */
@RestController
@Slf4j
public class SpiderInfoController {
    @Autowired
    SpiderCpuInfoService spiderCpuInfoService;
    /**
     * 抓取Cpu数据
     *
     * @return 是否抓取成功
     */
    @GetMapping("grabCpu")
    public Result grabCpuData() {
        try {
            spiderCpuInfoService.executeSaveData();
            return Result.success("200", "抓取数据并持久化成功", null);
        } catch (Exception e) {
            log.info("处理数据及持久化过程出现异常");
            e.printStackTrace();
            return Result.error("410", "抓取数据及持久化过程异常，请查看原因");
        }
    }
}
